package com.ABdolphin.forum.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;

@Data
public class AppResult<T> {
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private long code;
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private String message;
    @JsonInclude(JsonInclude.Include.ALWAYS)
    private T data;

    public AppResult() {
    }

    public AppResult( String message) {
        this.code = code;
        this.message = message;
    }

    public AppResult(long code, String message) {
        this.code = code;
        this.message = message;
    }
    public AppResult(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    public AppResult(long code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static AppResult success(){
        return new AppResult(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage());
    }
    public static <T> AppResult<T> success(T data){
        return new AppResult(ResultCode.SUCCESS.getCode(),ResultCode.SUCCESS.getMessage(),data);
    }
    public static <T> AppResult<T> success(String message, T data){
        return new AppResult(ResultCode.SUCCESS.getCode(),message ,data);
    }
    public static AppResult fail(){
        return new AppResult(ResultCode.FAILED.getCode(),ResultCode.FAILED.getMessage());
    }
    public static AppResult fail(ResultCode resultCode){
        return new AppResult(resultCode.getCode(), resultCode.getMessage());
    }
    public static AppResult fail(ResultCode resultCode,String message){
        return new AppResult(resultCode.getCode(),message);
    }
    public static AppResult fail(String message){
        return new AppResult(ResultCode.FAILED.getCode(),message);
    }
    public static <T>AppResult<T> fail(String message,T data){
        return new AppResult(ResultCode.FAILED.getCode(),message,data);
    }
}
